package o;

import android.util.Pair;
import androidx.annotation.Nullable;
import o.abr.c;
import o.abr.e;
import o.aim.a;

final class abo {
    private int ʻ;
    @Nullable
    private abj ʼ;
    private boolean ʽ;
    private int ˊ;
    private abr ˋ = abr.ˊ;
    private final c ˎ = new c();
    private long ˏ;
    private long ͺ;
    private final e ॱ = new e();
    @Nullable
    private Object ॱˊ;
    @Nullable
    private abj ॱॱ;
    @Nullable
    private abj ᐝ;

    public void ˊ(abr o_abr) {
        this.ˋ = o_abr;
    }

    public boolean ॱ(int i) {
        this.ˊ = i;
        return ʻ();
    }

    public boolean ˊ(boolean z) {
        this.ʽ = z;
        return ʻ();
    }

    public boolean ˏ(aih o_aih) {
        return this.ᐝ != null && this.ᐝ.ˎ == o_aih;
    }

    public void ˊ(long j) {
        if (this.ᐝ != null) {
            this.ᐝ.ˊ(j);
        }
    }

    public boolean ॱ() {
        return this.ᐝ == null || (!this.ᐝ.ʻ.ᐝ && this.ᐝ.ॱ() && this.ᐝ.ʻ.ˏ != -9223372036854775807L && this.ʻ < 100);
    }

    @Nullable
    public abl ˏ(long j, abp o_abp) {
        if (this.ᐝ == null) {
            return ˏ(o_abp);
        }
        return ˏ(this.ᐝ, j);
    }

    public aih ˋ(abm[] o_abmArr, alb o_alb, alc o_alc, aim o_aim, abl o_abl) {
        long j;
        if (this.ᐝ == null) {
            j = o_abl.ˊ;
        } else {
            j = this.ᐝ.ʻ.ˏ + this.ᐝ.ˋ();
        }
        abj o_abj = new abj(o_abmArr, j, o_alb, o_alc, o_aim, o_abl);
        if (this.ᐝ != null) {
            amm.ˏ(ॱॱ());
            this.ᐝ.ॱॱ = o_abj;
        }
        this.ॱˊ = null;
        this.ᐝ = o_abj;
        this.ʻ++;
        return o_abj.ˎ;
    }

    public abj ˊ() {
        return this.ᐝ;
    }

    public abj ˋ() {
        return this.ॱॱ;
    }

    public abj ˎ() {
        return this.ʼ;
    }

    public abj ˏ() {
        return ॱॱ() ? this.ॱॱ : this.ᐝ;
    }

    public boolean ॱॱ() {
        return this.ॱॱ != null;
    }

    public abj ᐝ() {
        boolean z = (this.ʼ == null || this.ʼ.ॱॱ == null) ? false : true;
        amm.ˏ(z);
        this.ʼ = this.ʼ.ॱॱ;
        return this.ʼ;
    }

    public abj ʽ() {
        if (this.ॱॱ != null) {
            if (this.ॱॱ == this.ʼ) {
                this.ʼ = this.ॱॱ.ॱॱ;
            }
            this.ॱॱ.ʼ();
            this.ʻ--;
            if (this.ʻ == 0) {
                this.ᐝ = null;
                this.ॱˊ = this.ॱॱ.ˋ;
                this.ͺ = this.ॱॱ.ʻ.ˎ.ˎ;
            }
            this.ॱॱ = this.ॱॱ.ॱॱ;
        } else {
            this.ॱॱ = this.ᐝ;
            this.ʼ = this.ᐝ;
        }
        return this.ॱॱ;
    }

    public boolean ˋ(abj o_abj) {
        boolean z = false;
        amm.ˏ(o_abj != null);
        this.ᐝ = o_abj;
        while (o_abj.ॱॱ != null) {
            o_abj = o_abj.ॱॱ;
            if (o_abj == this.ʼ) {
                this.ʼ = this.ॱॱ;
                z = true;
            }
            o_abj.ʼ();
            this.ʻ--;
        }
        this.ᐝ.ॱॱ = null;
        return z;
    }

    public void ˋ(boolean z) {
        abj ˏ = ˏ();
        if (ˏ != null) {
            this.ॱˊ = z ? ˏ.ˋ : null;
            this.ͺ = ˏ.ʻ.ˎ.ˎ;
            ˏ.ʼ();
            ˋ(ˏ);
        } else if (!z) {
            this.ॱˊ = null;
        }
        this.ॱॱ = null;
        this.ᐝ = null;
        this.ʼ = null;
        this.ʻ = 0;
    }

    public boolean ॱ(a aVar, long j) {
        int ˎ = this.ˋ.ˎ(aVar.ˋ);
        abj o_abj = null;
        abj ˏ = ˏ();
        while (ˏ != null) {
            if (o_abj == null) {
                ˏ.ʻ = ˋ(ˏ.ʻ);
            } else if (ˎ == -1 || !ˏ.ˋ.equals(this.ˋ.ˋ(ˎ))) {
                boolean z;
                if (ˋ(o_abj)) {
                    z = false;
                } else {
                    z = true;
                }
                return z;
            } else {
                abl ˏ2 = ˏ(o_abj, j);
                if (ˏ2 != null) {
                    ˏ.ʻ = ˋ(ˏ.ʻ);
                    if (!ॱ(ˏ, ˏ2)) {
                        if (ˋ(o_abj)) {
                            return false;
                        }
                        return true;
                    }
                } else if (ˋ(o_abj)) {
                    return false;
                } else {
                    return true;
                }
            }
            if (ˏ.ʻ.ˋ) {
                ˎ = this.ˋ.ˎ(ˎ, this.ˎ, this.ॱ, this.ˊ, this.ʽ);
            }
            o_abj = ˏ;
            ˏ = ˏ.ॱॱ;
        }
        return true;
    }

    public abl ˋ(abl o_abl) {
        boolean ˏ = ˏ(o_abl.ˎ);
        boolean ˎ = ˎ(o_abl.ˎ, ˏ);
        this.ˋ.ॱ(o_abl.ˎ.ˋ, this.ˎ);
        long ˊ = o_abl.ˎ.ˊ() ? this.ˎ.ˊ(o_abl.ˎ.ॱ, o_abl.ˎ.ˊ) : o_abl.ˎ.ˏ == Long.MIN_VALUE ? this.ˎ.ˏ() : o_abl.ˎ.ˏ;
        return new abl(o_abl.ˎ, o_abl.ˊ, o_abl.ॱ, ˊ, ˏ, ˎ);
    }

    public a ॱ(Object obj, long j) {
        return ॱ(obj, j, ˏ(obj));
    }

    private a ॱ(Object obj, long j, long j2) {
        this.ˋ.ॱ(obj, this.ˎ);
        int ˋ = this.ˎ.ˋ(j);
        if (ˋ == -1) {
            long j3;
            int ˏ = this.ˎ.ˏ(j);
            if (ˏ == -1) {
                j3 = Long.MIN_VALUE;
            } else {
                j3 = this.ˎ.ˋ(ˏ);
            }
            return new a(obj, j2, j3);
        }
        return new a(obj, ˋ, this.ˎ.ˎ(ˋ), j2);
    }

    private long ˏ(Object obj) {
        abj ˏ;
        int i = this.ˋ.ॱ(obj, this.ˎ).ॱ;
        if (this.ॱˊ != null) {
            int ˎ = this.ˋ.ˎ(this.ॱˊ);
            if (ˎ != -1 && this.ˋ.ˏ(ˎ, this.ˎ).ॱ == i) {
                return this.ͺ;
            }
        }
        for (ˏ = ˏ(); ˏ != null; ˏ = ˏ.ॱॱ) {
            if (ˏ.ˋ.equals(obj)) {
                return ˏ.ʻ.ˎ.ˎ;
            }
        }
        for (ˏ = ˏ(); ˏ != null; ˏ = ˏ.ॱॱ) {
            int ˎ2 = this.ˋ.ˎ(ˏ.ˋ);
            if (ˎ2 != -1 && this.ˋ.ˏ(ˎ2, this.ˎ).ॱ == i) {
                return ˏ.ʻ.ˎ.ˎ;
            }
        }
        long j = this.ˏ;
        this.ˏ = 1 + j;
        return j;
    }

    private boolean ॱ(abj o_abj, abl o_abl) {
        abl o_abl2 = o_abj.ʻ;
        return o_abl2.ˊ == o_abl.ˊ && o_abl2.ˎ.equals(o_abl.ˎ);
    }

    private boolean ʻ() {
        abj ˏ = ˏ();
        if (ˏ == null) {
            return true;
        }
        boolean ˋ;
        int ˎ = this.ˋ.ˎ(ˏ.ˋ);
        abj o_abj = ˏ;
        while (true) {
            ˎ = this.ˋ.ˎ(ˎ, this.ˎ, this.ॱ, this.ˊ, this.ʽ);
            while (o_abj.ॱॱ != null && !o_abj.ʻ.ˋ) {
                o_abj = o_abj.ॱॱ;
            }
            if (ˎ == -1 || o_abj.ॱॱ == null || this.ˋ.ˎ(o_abj.ॱॱ.ˋ) != ˎ) {
                ˋ = ˋ(o_abj);
                o_abj.ʻ = ˋ(o_abj.ʻ);
            } else {
                o_abj = o_abj.ॱॱ;
            }
        }
        ˋ = ˋ(o_abj);
        o_abj.ʻ = ˋ(o_abj.ʻ);
        if (ˋ && ॱॱ()) {
            ˋ = false;
        } else {
            ˋ = true;
        }
        return ˋ;
    }

    private abl ˏ(abp o_abp) {
        return ˏ(o_abp.ॱ, o_abp.ˏ, o_abp.ˋ);
    }

    @Nullable
    private abl ˏ(abj o_abj, long j) {
        abl o_abl = o_abj.ʻ;
        long ˋ = (o_abj.ˋ() + o_abl.ˏ) - j;
        int ˎ;
        int i;
        Pair ˋ2;
        long j2;
        if (o_abl.ˋ) {
            ˎ = this.ˋ.ˎ(this.ˋ.ˎ(o_abl.ˎ.ˋ), this.ˎ, this.ॱ, this.ˊ, this.ʽ);
            if (ˎ == -1) {
                return null;
            }
            i = this.ˋ.ॱ(ˎ, this.ˎ, true).ॱ;
            Object obj = this.ˎ.ˋ;
            long j3 = o_abl.ˎ.ˎ;
            if (this.ˋ.ˎ(i, this.ॱ).ʽ == ˎ) {
                ˋ2 = this.ˋ.ˋ(this.ॱ, this.ˎ, i, -9223372036854775807L, Math.max(0, ˋ));
                if (ˋ2 == null) {
                    return null;
                }
                long j4;
                Object obj2 = ˋ2.first;
                j3 = ((Long) ˋ2.second).longValue();
                if (o_abj.ॱॱ == null || !o_abj.ॱॱ.ˋ.equals(obj2)) {
                    j4 = this.ˏ;
                    this.ˏ = 1 + j4;
                } else {
                    j4 = o_abj.ॱॱ.ʻ.ˎ.ˎ;
                }
                obj = obj2;
                j2 = j3;
                j3 = j4;
            } else {
                j2 = 0;
            }
            return ˏ(ॱ(obj, j2, j3), j2, j2);
        }
        a aVar = o_abl.ˎ;
        this.ˋ.ॱ(aVar.ˋ, this.ˎ);
        int i2;
        if (aVar.ˊ()) {
            i2 = aVar.ॱ;
            ˎ = this.ˎ.ˊ(i2);
            if (ˎ == -1) {
                return null;
            }
            i = this.ˎ.ˎ(i2, aVar.ˊ);
            if (i >= ˎ) {
                j2 = o_abl.ॱ;
                if (this.ˎ.ˎ() == 1 && this.ˎ.ˋ(0) == 0) {
                    ˋ2 = this.ˋ.ˋ(this.ॱ, this.ˎ, this.ˎ.ॱ, -9223372036854775807L, Math.max(0, ˋ));
                    if (ˋ2 == null) {
                        return null;
                    }
                    j2 = ((Long) ˋ2.second).longValue();
                }
                return ˎ(aVar.ˋ, j2, aVar.ˎ);
            } else if (this.ˎ.ॱ(i2, i)) {
                return ॱ(aVar.ˋ, i2, i, o_abl.ॱ, aVar.ˎ);
            } else {
                return null;
            }
        } else if (o_abl.ˎ.ˏ != Long.MIN_VALUE) {
            i2 = this.ˎ.ˋ(o_abl.ˎ.ˏ);
            if (i2 == -1) {
                return ˎ(aVar.ˋ, o_abl.ˎ.ˏ, aVar.ˎ);
            }
            i = this.ˎ.ˎ(i2);
            if (this.ˎ.ॱ(i2, i)) {
                return ॱ(aVar.ˋ, i2, i, o_abl.ˎ.ˏ, aVar.ˎ);
            }
            return null;
        } else {
            ˎ = this.ˎ.ˎ();
            if (ˎ == 0) {
                return null;
            }
            i2 = ˎ - 1;
            if (this.ˎ.ˋ(i2) != Long.MIN_VALUE || this.ˎ.ˏ(i2)) {
                return null;
            }
            i = this.ˎ.ˎ(i2);
            if (!this.ˎ.ॱ(i2, i)) {
                return null;
            }
            return ॱ(aVar.ˋ, i2, i, this.ˎ.ˏ(), aVar.ˎ);
        }
    }

    private abl ˏ(a aVar, long j, long j2) {
        this.ˋ.ॱ(aVar.ˋ, this.ˎ);
        if (!aVar.ˊ()) {
            return ˎ(aVar.ˋ, j2, aVar.ˎ);
        } else if (!this.ˎ.ॱ(aVar.ॱ, aVar.ˊ)) {
            return null;
        } else {
            return ॱ(aVar.ˋ, aVar.ॱ, aVar.ˊ, j, aVar.ˎ);
        }
    }

    private abl ॱ(Object obj, int i, int i2, long j, long j2) {
        a aVar = new a(obj, i, i2, j2);
        boolean ˏ = ˏ(aVar);
        boolean ˎ = ˎ(aVar, ˏ);
        return new abl(aVar, i2 == this.ˎ.ˎ(i) ? this.ˎ.ॱ() : 0, j, this.ˋ.ॱ(aVar.ˋ, this.ˎ).ˊ(aVar.ॱ, aVar.ˊ), ˏ, ˎ);
    }

    private abl ˎ(Object obj, long j, long j2) {
        long j3;
        long ˏ;
        int ˏ2 = this.ˎ.ˏ(j);
        if (ˏ2 == -1) {
            j3 = Long.MIN_VALUE;
        } else {
            j3 = this.ˎ.ˋ(ˏ2);
        }
        a aVar = new a(obj, j2, j3);
        this.ˋ.ॱ(aVar.ˋ, this.ˎ);
        boolean ˏ3 = ˏ(aVar);
        boolean ˎ = ˎ(aVar, ˏ3);
        if (j3 == Long.MIN_VALUE) {
            ˏ = this.ˎ.ˏ();
        } else {
            ˏ = j3;
        }
        return new abl(aVar, j, -9223372036854775807L, ˏ, ˏ3, ˎ);
    }

    private boolean ˏ(a aVar) {
        boolean z = false;
        int ˎ = this.ˋ.ॱ(aVar.ˋ, this.ˎ).ˎ();
        if (ˎ == 0) {
            return true;
        }
        int i = ˎ - 1;
        boolean ˊ = aVar.ˊ();
        if (this.ˎ.ˋ(i) == Long.MIN_VALUE) {
            int ˊ2 = this.ˎ.ˊ(i);
            if (ˊ2 == -1) {
                return false;
            }
            boolean z2;
            if (ˊ && aVar.ॱ == i && aVar.ˊ == ˊ2 - 1) {
                z2 = true;
            } else {
                z2 = false;
            }
            if (z2 || (!ˊ && this.ˎ.ˎ(i) == ˊ2)) {
                z = true;
            }
            return z;
        } else if (ˊ || aVar.ˏ != Long.MIN_VALUE) {
            return false;
        } else {
            return true;
        }
    }

    private boolean ˎ(a aVar, boolean z) {
        int ˎ = this.ˋ.ˎ(aVar.ˋ);
        return !this.ˋ.ˎ(this.ˋ.ˏ(ˎ, this.ˎ).ॱ, this.ॱ).ˋ && this.ˋ.ˊ(ˎ, this.ˎ, this.ॱ, this.ˊ, this.ʽ) && z;
    }
}
